package com.yihusitian.zsxq.sg.filter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @Author LeeHo
 * @Date 2020/8/26 16:22
 */
public class FilterChain implements Filter {

    List<Filter> filters = new ArrayList<>();

    private int index = 0;

    public FilterChain addFilter(Filter filter) {
        filters.add(filter);
        return this;
    }

    @Override
    public void doFilter(FilterChain filterChain) {
        if (index == filters.size()) return;
        Filter filter = filters.get(index);
        index++;
        filter.doFilter(filterChain);
    }
}